package viz_main;

import java.awt.Color;

import processing.core.PApplet;
import view.V_DisplayObject;
/*
 * The TreeComponent is a visual representation of a tree Node in our system.
 * Right now it doesn't need much functionality but later on we may want it to be very dynamic and probably animate 
 * 
 */
public class TreeComponent extends V_DisplayObject { 
	/* Any component that has a width/height, x/y, color, and can be displayed in our system will typically extend 
	 * V_DisplayObject. 
	 * 
	 * Please refer to that class in the view package to get a sense of the methods and variables it provides.
	 * Mostly these are a bunch of useful utilities for getting and setting different properties or multiple properties at once.
	 */
	public static final float BASE_ALPHA = 0.5f;
	//public static final float BASE_COLOR = 1.0f;
	
	private boolean selected = false;
	private String name;
	private float opacity = 0.5f;
	private float strokeSize = 1.0f;
	private int strokeColor = 0;
	private Node treeNode;
	private int col = -1;
	private float tmpHeight, tmpWidth, tmpSize;
	private boolean isInner = false;
	
	// Constructor: 
	// for now you'll probably want to instantiate a new array of bars whenever the x-axis changes
	// later on we'll do what i mentioned in the TODO and we'll have to handle it a bit more delicately
	public TreeComponent(float xVal, float yVal, float wt , float ht, int c, Node n)// parameters will probably be x, y, width, height and color?
	{
		init(xVal, yVal, wt, ht); //offset the yPos to draw a rectangle from the top left corner
		this.setBGColor(c);
		this.visible = true;
		treeNode = n;
	}
		  
	// Update method for displaying this bar:
	  public void display(PApplet p) 
	  {
		  p.stroke(0);
	    if(visible)
	    {
	      p.strokeWeight(strokeSize);
	      
	      
	      if(isInner)
	      {
	    	  p.stroke(100);
	      }
	      
	      if(selected) {
	    	  p.fill(50,220,210,100);
	    	  if(isInner)
		      {
	    		  p.fill(50,220,210,220);
		      }
		  }
	      else {
	    	  p.fill(bgColor >> 16 & 0xFF, bgColor >> 8 & 0xFF, bgColor & 0xFF, (bgColor >> 24 & 0xFF)*opacity);
	      }

	      p.rect(xLoc, yLoc, xSize, ySize);
	    }
	  }
	  
	public Node getNode() {
		return treeNode;
	}
		
	public float getTmpHeight() {
		return tmpHeight;
	}

	public void setTmpHeight(float tmpHeight) {
		this.tmpHeight = tmpHeight;
	}

	public float getTmpWidth() {
		return tmpWidth;
	}

	public void setTmpWidth(float tmpWidth) {
		this.tmpWidth = tmpWidth;
	}
	
	public float getTmpSize() {
		return tmpSize;
	}

	public void setTmpSize(float sz) {
		this.tmpSize = sz;
	}

	public void setName(String nm) {
		name = nm;
	}
	
	public String getName() {
		return name;
	}
		  
	public void setSize(float val) {
		xSize = val;
		ySize = val;
	}
	  
	// offset the current x and y position by this much
	public void offset(float valX, float valY)
	{
		xLoc += valX;
		yLoc += valY;
	}
	  
	public void setColor(int c){
		col = c;
	}
	
	public void setOpacity(float val){
		opacity = val;
	}
	
	public void setStrokeSize(float val){
		strokeSize = val;
	}
	
	public void setStrokeColor(int val){
		strokeColor = val;
	}
	
	public void setIsInner(boolean val){
		isInner = val;
	}
	  
	public void setSelected(boolean val)
	{
		selected = val;
	}
}
